package com.study.threadLocal;

import java.util.concurrent.TimeUnit;

/**
 * ThreadLocal用法展示
 */
public class ThreadLocalDemo {

    public static final ThreadLocal<String> THREAD_LOCAL = new ThreadLocal<>();

    public static void main(String[] args) throws Exception {
        THREAD_LOCAL.set("哈哈哈");
        System.out.println("主线程ThreadLocal值：" + THREAD_LOCAL.get());
        new Thread(new Runnable() {
            @Override
            public void run() {
                THREAD_LOCAL.set("新线程ThreadLocal值：" + "嘿嘿嘿");
                System.out.println(THREAD_LOCAL.get());
            }
        }).start();
        TimeUnit.SECONDS.sleep(5);
        System.out.println("主线程ThreadLocal值：" + THREAD_LOCAL.get());
    }

}
